Introduce formDataArrayFormat option
#1901
Open
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR adds a new
formDataArrayFormatoption toLinkandrouter.visitthat duplicates the logic ofqueryStringArrayFormat, but for formData arrays serialization.Rationale
Currently, multipart form data arrays are always serialized using indices:
Rails (or more precisely Rack) parses this as hashes with keys
'0'and'1'. To support scenarios like a file input with themultipleattribute, we need to allow the tweaking of this behavior.This PR introduces the
formDataArrayFormatoption torouter.visit. With this option set to'brackets', we serialize the keys in the format required by Rack/Rails:Notes
I have set
formDataArrayFormatto'indices'by default to preserve the current behavior. We might want to synchronizeformDataArrayFormatandqueryStringArrayFormatvalues at some point (or even introduce more general option), but this could be a breaking change.